local json = require "cjson"

local function main (userOb, msgData)
    if not msgData.context then
        return
    end

    if string.len(msgData.context) > 4096 then
        local result = {}
        result.error = 1
        userOb:send_packet("MSGS2CUploadPlayerDbase", result)
        return
    end

    local ok, player_dbase = pcall(json.decode, msgData.context)
    if not ok then
        local result = {}
        result.error = 2
        userOb:send_packet("MSGS2CUploadPlayerDbase", result)
        return
    end

    userOb:set("player_dbase", player_dbase)

    ---! 同步关卡排名
    RANK_D:sync_rank_data(userOb)

    local result = {}
    result.error = 0
    userOb:send_packet("MSGS2CUploadPlayerDbase", result)
end

COMMAND_D:register_command("MSGC2SUploadPlayerDbase", GameCmdType.NONE, main)
